-- SPDX-License-Identifier: GPL-3.0-or-later

local extension = Package("vupslash_special_cards_2", Package.CardPack)
-- extension.extensionName = "vupslash"
extension.extensionName = "VslTest"

-- Fk:loadTranslationTable{
--   ["standard"] = "Vup杀基本卡牌",
-- }

-- local VslUtil = require "packages/vupslash/util"
local VslUtil = require "packages/VslTest/util"

local slash = Fk:cloneCard(VslUtil.Slash)

--------------------------------------------------
--冰杀
--------------------------------------------------

local ice_v_SlashSkill = fk.CreateActiveSkill{
  name = "ice__"..VslUtil.IceSlash.."_skill",
  max_phase_use_time = 1,
  target_num = 1,
  can_use = slash.skill.canUse,
  mod_target_filter = slash.skill.modTargetFilter,
  target_filter = slash.skill.targetFilter,
  on_effect = function(self, room, effect)
    local to = effect.to
    local from = effect.from

    room:damage({
      from = room:getPlayerById(from),
      to = room:getPlayerById(to),
      card = effect.card,
      -- damage = 1 + (effect.additionalDamage or 0),
      damage = 1,
      damageType = fk.IceDamage,
      skillName = self.name
    })
  end
}
local v_iceSlash = fk.CreateBasicCard{
  name = VslUtil.IceSlash,
  skill = ice_v_SlashSkill,
  is_damage_card = true,
}

extension:addCards{
  v_iceSlash:clone(Card.Club, 7),
  v_iceSlash:clone(Card.Club, 8),
}

-- Fk:loadTranslationTable{
-- 	["v_ice__slash"] = "冰杀",
-- 	[":v_ice__slash"] = "基本牌<br /><b>时机</b>：出牌阶段<br /><b>目标</b>：攻击范围内的一名角色<br /><b>效果</b>：对目标角色造成1点冰霜伤害。",
-- }

--------------------------------------------------
--衍生牌：魔法剑
--------------------------------------------------

local v_magic_sword_filter = fk.CreateFilterSkill{
  name = "#v_magic_sword_filter",
  card_filter = function(self, card, player)
    if type(player:getMark("#v_magic_sword_skill")) == "table" then
      return card.id == player:getMark("#v_magic_sword_skill")[1]
    end
  end,
  view_as = function(self, card, player)
    if type(player:getMark("#v_magic_sword_skill")) == "table" then
      local su = VslUtil.suit_number(player:getMark("#v_magic_sword_skill")[2])    
      return Fk:cloneCard(card.name, su, card.number)
    end
  end,
}
local v_magic_swordSkill = fk.CreateTriggerSkill{
  name = "#v_magic_sword_skill",
  anim_type = "control",
  frequency = Skill.Compulsory, --如果这个会覆盖on_cost则删除
  events = {fk.AskForRetrial},
  --触发条件：（已完成）
  -- 遍历到的角色具有武器
  -- 遍历到的角色的武器class_name为魔法剑
  -- 本回合只使用过一次本技能
  -- （待补充）遍历到的角色可以使用武器
  can_trigger = function(self, event, target, player, data)
    local weapon1 = player:getEquipment(Card.SubtypeWeapon)
    return weapon1
      -- and Fk:getCardById(weapon1).class_name == "v_Magicsword" --待定
      and Fk:getCardById(weapon1).name == "v_magic_sword" --待定
      and player:usedSkillTimes(self.name, Player.HistoryTurn) == 0
  end,
  --使用询问：
  --改编一下prompt正常询问即可。
  on_cost = function(self, event, target, player, data)
    local room = player.room
    --确认是否发动技能。
    local prompt = "v_magic_sword_choice:"..target.id.."::"..data.reason
    if room:askForSkillInvoke(player, self.name, data, prompt) then
      return true
    end
  end,
  --使用流程：
  --先提供选择，然后将花色和牌作为标记，判定结束后解除。
  --提供额外的filter技能在判定期间将魔法剑视为其他花色
  on_use = function(self, event, target, player, data)
    local room = player.room
    if target ~= player then
      --doindicate的两个参数一个为integer，一个为table
      room:doIndicate(player.id, { target.id })
    end
    local prompt = "v_magic_sword_change"
    local choice = room:askForChoice(player, VslUtil.suits, self.name, prompt)
    local card_id = player:getEquipment(Card.SubtypeWeapon)
    local card = Fk:getCardById(card_id)
    room:setPlayerMark(target, self.name, {card_id, choice})
    room:retrial(card, player, data, self.name, false)
  end,

  refresh_events = {fk.FinishJudge},
  can_refresh = function(self, event, target, player, data)
    return player:getMark(self.name) ~= 0
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, self.name, 0)
  end,
}
v_magic_swordSkill:addRelatedSkill(v_magic_sword_filter)

Fk:addSkill(v_magic_swordSkill)

local v_magic_sword = fk.CreateWeapon{
  name = "&v_magic_sword",
  -- class_name = "v_Magicsword", --待定
  -- suit = Card.Heart,
  -- number = 3,
  attack_range = 2,
  equip_skill = v_magic_swordSkill,
}

extension:addCards{
  v_magic_sword:clone(Card.Heart, 3),
}
-- extension:addCards(v_magicsword)

-- Fk:loadTranslationTable{
-- 	["v_magicsword"] = "魔法剑",
-- 	["#v_magicsword_skill"] = "魔法剑",
-- 	["#v_magicsword_filter"] = "魔法剑",
-- 	[":v_magicsword"] = "<font color='#008080'>特殊牌</font><br />装备牌·武器<br /><b>攻击范围：</b>２<br /><b>武器技能：</b>每回合限一次，当判定牌生效前，你可以将此牌视为任意花色的牌代替之。",
-- 	["v_magicsword_choice"] = "你可以用魔法剑代替 %src 的 %arg 判定牌<br/>魔法剑可以视为任意花色的牌",
-- 	["v_magicsword_change"] = "请选择所需花色。",
-- 	-- ["#v_magicsword_change_suit"] = "%from 令 %card 在本次 %arg 判定中视为 %arg2 牌",
-- 	-- ["regard_as_spade"] = "视为黑桃",
-- 	-- ["regard_as_club"] = "视为梅花",
-- 	-- ["regard_as_heart"] = "视为红桃",
-- 	-- ["regard_as_diamond"] = "视为方块",

-- }

-- 加载本包的翻译包(load translations of this package)，这一步在本文档的最后进行。
-- dofile "packages/vupslash/i18n/init.lua"
dofile "packages/VslTest/i18n/init.lua"

return extension
